package cn.mihoyo.basic.service.impl;

import cn.mihoyo.basic.mapper.BasicMapper;
import cn.mihoyo.basic.query.BasicQuery;
import cn.mihoyo.basic.service.BasicService;
import cn.mihoyo.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public abstract class BasicServiceImpl<T> implements BasicService<T> {
    @Autowired
    private BasicMapper<T> basicMapper;


    @Override
    public void add(T t) {
        basicMapper.add(t);
    }

    public void delete(Long id) {
        basicMapper.delete(id);
    }

    @Override
    public void update(T t) {
        basicMapper.update(t);
    }


    @Override
    public T findById(Long id) {
        return basicMapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return basicMapper.findAll();
    }

    @Override
    public PageList<T> queryByPage(BasicQuery query) {
        Integer totals = basicMapper.queryCount(query);
        if(totals == 0||totals == null) {
            return new PageList<>(0,new ArrayList<>());
        }
        List<T> ts = basicMapper.queryByPage(query);
        return new PageList<>(totals,ts);
    }

    @Override
    public void batchDel(List<Long> ids) {
        basicMapper.batchDel(ids);
    }

}
